﻿using System;
using Web.Entities.Enums;

namespace Web.HelperClasses.Inflexion
{
	public class WordFormatter : IWordFormatter
	{
		private readonly IInflector inflector;

		public WordFormatter(IInflector inflector)
		{
			this.inflector = inflector;
		}

		public string GetNumericalWordForm(string word, int number)
		{
			number = Math.Abs(number);
			int rem10 = number % 10;
			int rem100 = number % 100;
			//1, 21, 31...
			if (rem10 == 1 && rem100 != 11)
				return word;
			//2, 3, 4, 22, 23, 24, 32...
			if ((rem10 == 2 || rem10 == 3 || rem10 == 4) && (rem100 - rem10) != 1)
				return inflector.Inflect(word, Case.Genitive, true);
			//0, 5, 6, 7, 8, 9, 10, 11, 12, .. , 20, 25...
			return inflector.Inflect(word, Case.Genitive, false);
		}
	}
}